#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sem.h>
#include <linux/sched.h>

struct completion my_completion1;
struct completion my_completion2;//定义了两个完成量

int thread_dirver(void *);
int thread_saleman(void *);

int thread_driver(void *p)//司机线程

{
	printk("DRIVER:I AM WAITING FOR SALEMAN CLOSED THE DOOR\n");
	wait_for_completion(&my_completion1);//等待完成量completion1

	printk("DRIVER:OK , LET’S GO!NOW~\n");
	printk("DRIVER:ARRIVE THE STATION.STOPED CAR!\n");
	complete(&my_completion2);//唤醒完成量completion2

	return 0;
}

int thread_saleman(void *p)//售票员线程
{
	printk("SALEMAN:THE DOOR IS CLOSED!\n");
	complete(&my_completion1);//唤醒完成量completion1

	printk("SALEMAN:YOU CAN GO NOW！\n");
	wait_for_completion(&my_completion2);//等待完成量completion2

	printk("SALEMAN:OK,THE DOOR BE OPENED!\n");
	return 0;
}
/*
	模块的初始化; lkp_init(); 
	 */

static int __init lkp_init(void)
{
	printk("hello,world\n"); 
	init_completion(&my_completion1);
	init_completion(&my_completion2);//初始化完成量

	kernel_create(thread_driver,NULL,CLONE_KERNEL);
	kernel_create(thread_saleman,NULL,CLONE_KERNEL);//创建了两个内核线程，
	return 0; 
}


/*
	 模块的退出和清理; 
	 */

static void __exit lkp_exit(void)
{
	printk("Goodbye everybody~\n"); 
}

module_init(lkp_init); 
module_exit(lkp_exit); 

/*
	模块的代码许可; 
	 */
MODULE_LICENSE("GPL"); 
